home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / MENUGADG.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  60 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Defines TMenuGadget
  8. //
  9. // A TMenuGadget is a text gadget that when pressed, it acts as a popup menu.
  10. //----------------------------------------------------------------------------
  11. #include <owl/pch.h>
  12. #if !defined(OWL_MENUGADG_H)
  13. # include <owl/menugadg.h>
  14. #endif
  15.  
  16. OWL_DIAGINFO;
  17.  
  18. const int MaxMenuTextLen = 512;
  19.  
  20. //
  21. // Create the popup menu and initialize the text gadget.
  22. //
  23. TMenuGadget::TMenuGadget(TMenu& menu, TWindow* window, int id,
  24.                          TBorderStyle borderStyle, char far* text, TFont* font)
  25. :
  26.   TTextGadget(id, borderStyle, TTextGadget::Left, 15, text, font),
  27.   CmdTarget(window)
  28. {
  29.   SetShrinkWrap(true, true);
  30.   PopupMenu = new TPopupMenu(menu);
  31.  
  32.   // initialize Text data member
  33.   //
  34.   char menuText[MaxMenuTextLen];
  35.   if (PopupMenu->GetMenuString(0, menuText, MaxMenuTextLen, MF_BYPOSITION))
  36.     SetText(menuText);
  37. }
  38.  
  39. //
  40. // Delete the allocated popup menu.
  41. //
  42. TMenuGadget::~TMenuGadget()
  43. {
  44.   delete PopupMenu;
  45. }
  46.  
  47. //
  48. // Popup menu on lbuttondown
  49. //
  50. void
  51. TMenuGadget::LButtonDown(uint modKeys, TPoint& p)
  52. {
  53.   TGadget::LButtonDown(modKeys, p);
  54.   TRect rect = GetBounds();
  55. //  GetInnerRect(rect);
  56.   TPoint p2(rect.TopLeft());
  57.   Window->ClientToScreen(p2);
  58.   PopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, p2, 0, *CmdTarget);
  59. }
  60.